package com.xnfh.planting.viewmodel

import com.xnfh.common.bean.FindFieldRecordS
import com.xnfh.framework.base.BaseStateObserver
import com.xnfh.framework.base.BaseViewModel
import com.xnfh.framework.bean.RespStateData
import org.json.JSONObject

/**
 * @Description:
 * @Author: ziheng
 * @CreateDate: 2023/12/15 18:05
 * @UpdateUser: ziheng
 * @UpdateDate: 2023/12/15 18:05
 * @UpdateRemark: 更新说明
 */
class FindFieldRecordsViewModel: BaseViewModel() {

    val findFieldRecordsViewModelRes = FindFieldRecordsViewModelRes()

    val findFieldRecords = RespStateData<FindFieldRecordS>()
    val findFieldRecordsDel = RespStateData<Any>()


    /**
     * 获取巡田记录列表
     */
    fun requestFindFieldRecords(fieldId: String?, current: Int) = launch {
        val jsonObject = JSONObject()
        jsonObject.put("fieldId",fieldId)
        jsonObject.put("current",current.toString())
        jsonObject.put("size",20)
        findFieldRecordsViewModelRes.requestFindFieldRecords(creatRequestBody(jsonObject.toString()),findFieldRecords)
    }

    /**
     * 删除巡田记录
     */
    fun requestDelFindField(id: String)=launch {
        val jsonObject = JSONObject()
        jsonObject.put("id",id)
        findFieldRecordsViewModelRes.requestDelFindField(creatRequestBody(jsonObject.toString()),findFieldRecordsDel)
    }

}